{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9d5a50d0",
   "metadata": {},
   "source": [
    "# Week05 数据结构列表\n",
    "* ###  用户输入方法：input()\n",
    "* ### 回顾上节课内容：登陆系统（while循环、input输入）\n",
    "* ### 本节：打印（print）输出的一般方法\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c116eb52",
   "metadata": {},
   "source": [
    "# 一、用户输入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "62c69451",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name:baobao\n",
      "age:20\n",
      "job:student\n",
      "salary:0\n"
     ]
    }
   ],
   "source": [
    "name = input(\"name:\")\n",
    "age = input(\"age:\")\n",
    "job = input(\"job:\")\n",
    "salary = input(\"salary:\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67b8346f",
   "metadata": {},
   "source": [
    "* ##    知识点1：字符串拼接 用+ 让打印的结果更直观"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a56aef2f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-----INFO OFbaobao------\n",
      "age:20\n",
      "job:student\n",
      "salary:0\n"
     ]
    }
   ],
   "source": [
    "info = '''-----INFO OF''' + name +'''------''' + '''\n",
    "age:''' + age+'''\n",
    "job:''' + job+'''\n",
    "salary:'''+salary\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7bcac279",
   "metadata": {},
   "outputs": [],
   "source": [
    "#   注释来写内容存到字符串中"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e3a00b2",
   "metadata": {},
   "source": [
    "* ## 知识点2：%s占位符，可以吧“+”符号省略，比较直观的展示变量内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d60a2bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "#   缺点： 如果变量很多，会比较麻烦"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "27536a7b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name:baobao\n",
      "age:20\n",
      "job:student\n",
      "salary:0\n",
      "-------INFO OF baobao -------\n",
      "Name:baobao\n",
      "Age:20\n",
      "Job:student\n",
      "Salary:0\n",
      "\n"
     ]
    }
   ],
   "source": [
    "name = input(\"name:\")\n",
    "age = input(\"age:\")\n",
    "job = input(\"job:\")\n",
    "salary = input(\"salary:\")\n",
    "\n",
    "info = '''-------INFO OF %s -------\n",
    "Name:%s\n",
    "Age:%s\n",
    "Job:%s\n",
    "Salary:%s\n",
    "'''% (name,name,age,job,salary)\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "69e0b217",
   "metadata": {},
   "outputs": [],
   "source": [
    "# %s代表string（字符串）\n",
    "# %d代表number（数字）\n",
    "# %f代表float(浮点型)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "20864332",
   "metadata": {},
   "source": [
    "### 设置数据类型，将age、salary设置为number"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "be3d086d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name:baobao\n",
      "age:20\n",
      "job:student\n",
      "salary:0\n",
      "-------INFO OF baobao -------\n",
      "name:baobao\n",
      "age:20\n",
      "job:student\n",
      "salary:0\n",
      "\n"
     ]
    }
   ],
   "source": [
    "name = input(\"name:\")\n",
    "age = int(input(\"age:\")) \n",
    "job = input(\"job:\")\n",
    "salary = int(input(\"salary:\"))\n",
    "\n",
    "info = '''-------INFO OF %s -------\n",
    "name:%s\n",
    "age:%d\n",
    "job:%s\n",
    "salary:%d\n",
    "'''% (name,name,age,job,salary)\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a290e817",
   "metadata": {},
   "source": [
    "* ##  知识点3： .format()  比起%s更适合较多变量的打印，不需要考量顺序和出现次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "2d5a166f",
   "metadata": {},
   "outputs": [],
   "source": [
    "#       例如 ： url的拼接 （https:// + 域名 + endpoint）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "697aef19",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "------INFO baobao ------\n",
      "name:baobao\n",
      "age:20\n",
      "job:student\n",
      "salary:0\n"
     ]
    }
   ],
   "source": [
    "info1 = '''------INFO {HTML_name} ------\n",
    "name:{HTML_name}\n",
    "age:{HTML_age}\n",
    "job:{HTML_job}\n",
    "salary:{HTML_salary}'''.format(HTML_name=name,HTML_age=age,HTML_job=job,HTML_salary=salary)\n",
    "\n",
    "print(info1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "2b022492",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['2021', '10', '27']\n",
      "27\n"
     ]
    }
   ],
   "source": [
    "# 假定你要求用户以2021-10-27 格式输入\n",
    "user_input_time = \"2021-10-27\"\n",
    "\n",
    "# 字符串拆分， 方法split\n",
    "print(user_input_time.split('-'))\n",
    "print(user_input_time.split('-')[2])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "44be1ea6",
   "metadata": {},
   "source": [
    "# 二、列表list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "0c83da32",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bbb\n"
     ]
    }
   ],
   "source": [
    "names = [\"aaa\",\"bbb\",\"ccc\"]\n",
    "print(names[1])\n",
    "users_list = [\"aaa\",\"bbb\",\"ccc\"]\n",
    "password_list = [123456,789654,234567]\n",
    "age_list = [18,19,20]\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6057f3fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 列表的嵌套"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "9a1e7f28",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aaa\n",
      "123456\n",
      "18\n",
      "['ccc', 234567, 20]\n"
     ]
    }
   ],
   "source": [
    "info_list = [[\"aaa\",123456,18],[\"bbb\",789654,19],[\"ccc\",234567,20]]\n",
    "\n",
    "print(users_list[0])\n",
    "print(password_list[0])\n",
    "print(age_list[0])\n",
    "\n",
    "print(info_list[-1])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ccae8287",
   "metadata": {},
   "source": [
    "* ## 知识点 slices(切片)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "346f39b2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['b', 'c']\n",
      "['a', 'b']\n",
      "['a', 'b']\n"
     ]
    }
   ],
   "source": [
    "names = [\"a\",\"b\",\"c\",\"d\"]\n",
    "\n",
    "# 1、正向取值\n",
    "\n",
    "# list 取值  “：”右边的值取不到 例如[1:3] 3这个位置取不到\n",
    "\n",
    "print(names[1:3])\n",
    "print(names[0:2])\n",
    "print(names[:2])\n",
    "\n",
    "# 如果，左侧的值是0，即从0开始取值，0可以省略不写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "39403999",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2、反向取值\n",
    "\n",
    "# list 取值“：”右边的值取不到，例如[-3:-1]中-1这个位置取不到"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "51d7329b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['b', 'c']\n",
      "['b', 'c', 'd']\n",
      "[]\n",
      "['b', 'c', 'd']\n"
     ]
    }
   ],
   "source": [
    "print(names[-3:-1])\n",
    "print(names[-3:])\n",
    "\n",
    "print(names[-3:0])\n",
    "print(names[-3:])\n",
    "# 注意： 取到最后一个值，不能写0，可以省略不写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "57e61202",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 0的值永远是首个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "c87d5a00",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
      "[1, 3, 5]\n"
     ]
    }
   ],
   "source": [
    "num = [1,2,3,4,5,6,7,8,9]\n",
    "# 对比 range\n",
    "\n",
    "print(list(range(10)))\n",
    "\n",
    "print(num[:6:2])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f427f44b",
   "metadata": {},
   "outputs": [],
   "source": [
    "#  ：6 取到第六个数7  ：2然后往前跳第二个数"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
